﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Demo
{
    class Program
    {
        static int count = 0;
        static int pcount = 0;
        static int ncount = 0;
        static Npc n = new Npc();
        static player p = new player();
        static ruler ruler = new ruler();
        enum chuquan
        {
            剪刀 = 1,
            石头,
            布
        }
        enum role
        {
            刘备 = 1,
            孙权,
            曹操
        }

        static void Main(string[] args)
        {
            start();

        }
        public static void start() {
            welcome();
            rule();
            ballte();
            result();
        }
        public static void welcome()
        {
            Console.WriteLine("——————欢迎进入游戏世界——————");
            Console.WriteLine("*********************");
            Console.WriteLine("****猜拳,开始*****");
            Console.WriteLine("*********************");

        }
        public static void rule()
        {
            while (true)
            {
                Console.WriteLine("出拳规则：1.剪刀 2.石头 3.布");
                Console.WriteLine("请选择对方角色 1.刘备 2.孙权 3.曹操");
                int num = int.Parse(Console.ReadLine());
                Console.WriteLine("请输入你的姓名");
                string name = Console.ReadLine();
                Console.WriteLine("{0}VS{1} 对战", name, num);
                Console.WriteLine("开始游戏吗（y/n）");
                string a = Console.ReadLine();
                if (a == "Y")
                {
                    break;
                }
            }

        }
        public static void ballte()
        {
            while (true)
            {
                Console.WriteLine("请出拳:{0}（输入相应数字）", ListPunch());
                int pf = p.print();
                int nf = n.print();
                Console.WriteLine("{0}出{1}",p.name,(chuquan)pf);
                Console.WriteLine("{0}出{1}",n.name,(chuquan)nf);
                int result = Iswin(pf,nf);
                Console.WriteLine();
                Console.WriteLine(result==0?"和局":result==1?$"恭喜{p.name}赢了":$"{p.name}输了");
                count++;
                if (result == 1) {
                    pcount++;
                }
                if (result == -1) {
                    ncount++;
                }
                Console.WriteLine("是否开始下一轮（y/n）");
                string key = Console.ReadLine();
                if (key == "n") {
                    break;
                }

            }
        }
        public static void result() {
            Console.WriteLine("\n================================");
            Console.WriteLine("{0}VS{1}",p.name,n.name);
            Console.WriteLine("对战次数{0}",count);
            Console.WriteLine();
            Console.WriteLine("姓名\t得分");
            Console.WriteLine("{0}\t{1}",p.name,pcount);
            Console.WriteLine("{0}\t{1}", n.name, ncount);
            Console.WriteLine("结果"+(pcount>ncount?p.name:n.name)+"赢了");
            Console.WriteLine("要开始下一局吗（y/n)");
            string key = Console.ReadLine();
            if (key == "y")
            {
                start();
            }
            else {
                Console.WriteLine("游戏结束");
            }
        }

        public static string ListPunch()
        {
            string punchString = " ";
            int i = 1;
            foreach (chuquan n in Enum.GetValues(typeof(chuquan)))
            {
                punchString += i + "、" + n + "；";
                i++;

            }
            return punchString;
        }
        public static string ListNpc()
        {
            string role = " ";
            int i = 1;
            foreach (role n in Enum.GetValues(typeof(role)))
            {
                role += i + "、" + n + "；";
                i++;

            }
            return role;
        }

        public static int Iswin(int pf,int nf) {
            if (pf == nf) {
                return 0;
            } else if (pf == 1 & nf == 3 || pf == 2 & nf == 1 || pf == 3 & nf == 2) {
                return 1;

            }
            else {
                return -1;
            }
        }
    }
}
